package cn.edu.nuc.ssm.services.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.nuc.ssm.dao.GoodsMapper;
import cn.edu.nuc.ssm.entity.Goods;
import cn.edu.nuc.ssm.services.interfaces.GoodsService;
import cn.edu.nuc.ssm.util.PageInfo;

@Service
public class GoodsServiceImp implements GoodsService {

	List<Goods> list;
	@Autowired
	private GoodsMapper goodsMapper;
	
	@Override
	public int add(Goods goods) {
		int ref = 0;
		
		ref = goodsMapper.insertSelective(goods);
		
		return ref;
	}

	@Override
	public PageInfo namelist(String gname, int current) {
		
		PageInfo pi = new PageInfo(current);		
		
		int count = goodsMapper.count(gname);
		
		pi.setCount(count);
		
		List<Goods> list =  goodsMapper.findByLikeName(gname, pi.getStart(), pi.getOffset());
		
		pi.setList(list);
		
		return pi;
	}

	@Override
	public Goods findById(int gid) {				
		return goodsMapper.selectByPrimaryKey(gid);
	}

	@Override
	public int update(Goods goods) {
		 
		return goodsMapper.updateByPrimaryKey(goods);
	}

	@Override
	public int delt(int gid) {
		
		return goodsMapper.deleteByPrimaryKey(gid);
	}

	
}
